package com.dream.keigezhushou.Activity.kege.acty;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.Uiutils.StringUtils;
import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.kege.adapter.MySingingDetailAdapter;
import com.dream.keigezhushou.Activity.pop.GiftPopWindow;
import com.dream.keigezhushou.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * 合唱详情
 */
public class SingingDetailActivity extends AppCompatActivity {


    @BindView(R.id.list_lv)
    PullToRefreshListView mMPullToRefreshListView;

    TextView sendFlowsTv;


    private TextView joinImage;
    private ImageView returnImg;
    private TextView singingDetailTv;
    private LinearLayout singsingNumberLinear;

    private CheckBox startEndCb;
    private ImageView singDetialIv;


    //礼物控件
    private LinearLayout detailGift;

    //礼物榜列表控件
    private LinearLayout detaiGiftList;


    private ListView mListlv;
    private View mHeadView;
    private MySingingDetailAdapter adapter;

    String getString;


    int[] giftList = {R.drawable.gift_icon, R.drawable.gift_icon, R.drawable.gift_icon, R.drawable.gift_icon, R.drawable.gift_icon, R.drawable.gift_icon};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_singing_detail);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        getString = intent.getStringExtra(StringUtils.KEGESTATE);
        initView();
//
//        for (int i = 0; i < giftList.length; i++) {
//            GiftBean giftBean = new GiftBean(giftList[i]);
//            GiftRankingView giftRankingView = new GiftRankingView(SingingDetailActivity.this, giftBean);
//            detaiGiftList.addView(giftRankingView);
//        }
        onClickView();
    }


    //初始化控件

    public void initView() {
        mMPullToRefreshListView.setMode(PullToRefreshBase.Mode.DISABLED);
        adapter = new MySingingDetailAdapter(SingingDetailActivity.this);
        mListlv = mMPullToRefreshListView.getRefreshableView();
        mHeadView = UiUtils.inflateView(R.layout.head_singing_detail);
        singDetialIv = (ImageView) mHeadView.findViewById(R.id.sing_detail_next);
        joinImage = (TextView) mHeadView.findViewById(R.id.singing_detail_join);
        returnImg = (ImageView) mHeadView.findViewById(R.id.ib_return);
        singingDetailTv = (TextView) mHeadView.findViewById(R.id.singing_detail_add_tv);
        singsingNumberLinear = (LinearLayout) mHeadView.findViewById(R.id.singing_detail_number_linear);
        detailGift = (LinearLayout) mHeadView.findViewById(R.id.singing_detail_gift);
        detaiGiftList = (LinearLayout) mHeadView.findViewById(R.id.detail_gift_list);
        startEndCb = (CheckBox) mHeadView.findViewById(R.id.sing_detail_start_end);
        sendFlowsTv = (TextView) mHeadView.findViewById(R.id.sing_detail_send_flows);


        if (getString.equals("听歌")) {
            singingDetailTv.setVisibility(View.GONE);
            singsingNumberLinear.setVisibility(View.GONE);
            detailGift.setVisibility(View.GONE);

        } else if (getString.equals("合唱")) {
            singingDetailTv.setVisibility(View.VISIBLE);
            singsingNumberLinear.setVisibility(View.VISIBLE);
            detailGift.setVisibility(View.VISIBLE);
//            joinImage.setText("合唱");
        } else if (getString.equals("参与列表")) {
            singingDetailTv.setVisibility(View.VISIBLE);
            singsingNumberLinear.setVisibility(View.VISIBLE);
            detailGift.setVisibility(View.VISIBLE);
//            joinImage.setText("合唱列表");

        } else if (getString.equals("Ｋ歌")) {
            singingDetailTv.setVisibility(View.VISIBLE);
            singsingNumberLinear.setVisibility(View.VISIBLE);
            detailGift.setVisibility(View.VISIBLE);
//            joinImage.setText("Ｋ歌");

        } else if (getString.equals("加入合唱")) {
            singingDetailTv.setVisibility(View.VISIBLE);
            singsingNumberLinear.setVisibility(View.VISIBLE);
            detailGift.setVisibility(View.VISIBLE);
            joinImage.setText("加入合唱");

        }


        mListlv.setAdapter(adapter);
        mListlv.addHeaderView(mHeadView);

    }


    //控件点击事件

    public void onClickView() {
        joinImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (joinImage.getText().equals("合唱")) {
                    Intent intent = new Intent();
                    intent.setClass(SingingDetailActivity.this, SongLyricsActivity.class);
                    startActivity(intent);
                } else if (joinImage.getText().equals("合唱列表")) {
                    Intent intent = new Intent();
                    intent.setClass(SingingDetailActivity.this, ChorusListActivity.class);
                    startActivity(intent);
                } else if (joinImage.getText().equals("Ｋ歌")) {
                    Intent intent = new Intent();
                    intent.setClass(SingingDetailActivity.this, RankingListActivity.class);
                    startActivity(intent);

                } else if (getString.equals("加入合唱")) {
                    Intent intent = new Intent();
                    intent.setClass(SingingDetailActivity.this, ChoralListActivity.class);
                    startActivity(intent);

                }
            }
        });


        returnImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        //礼物榜点击事件
        detailGift.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(SingingDetailActivity.this, GiftListActivity.class);
                startActivity(intent);
            }
        });


        startEndCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            }
        });


        //送花

        sendFlowsTv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final GiftPopWindow giftPopWindow = new GiftPopWindow(View.inflate(SingingDetailActivity.this, R.layout.pop_gift_ranking, null), SingingDetailActivity.this, UiUtils.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
                giftPopWindow.showPopAtLocation(v, Gravity.BOTTOM);
                giftPopWindow.setItemListener(new GiftPopWindow.ItemClickListener() {
                    @Override
                    public void onClick() {
                        UiUtils.toast("成功赠送了鲜花");
                        giftPopWindow.dismiss();
                    }

                    @Override
                    public void onSingDetail(View view) {

                        giftPopWindow.dismiss();

                    }
                });


            }
        });


    }


}
